//
//  main.c
//  线性表链式存储设计与实现
//
//  Created by ZJ on 2018/7/13.
//  Copyright © 2018年 iCatch Technology Inc. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include "linklist.h"

typedef struct Teacher {
    LinkListNode node; // 第一个域（第一个元素）
    int age;
    char name[64];
}Teacher;

int main(int argc, const char * argv[]) {
    // insert code here...
    int len = 0;
    int ret = 0;
    
    LinkList *list = NULL;
    
    Teacher t1, t2, t3, t4, t5;
    t1.age = 31;
    t2.age = 32;
    t3.age = 33;
    t4.age = 34;
    t5.age = 35;
    
    list = LinkList_Create();
    if (list == NULL) {
        return -1;
    }
    
    // 获取长度
    len = LinkList_Length(list);
    printf("len: %d\n", len);

    // 插入 链表的算法和具体业务节点分离
    ret = LinkList_Insert(list, (LinkListNode *)&t1, 0);
    ret = LinkList_Insert(list, (LinkListNode *)&t2, 0);
    ret = LinkList_Insert(list, (LinkListNode *)&t3, 0);
    ret = LinkList_Insert(list, (LinkListNode *)&t4, 0);
    ret = LinkList_Insert(list, (LinkListNode *)&t5, 0);

    len = LinkList_Length(list);
    printf("len: %d\n", len);
    
    // 遍历
    for (int i = 0; i < LinkList_Length(list); i++) {
        Teacher *tmp = (Teacher *)LinkList_Get(list, i);
        if (tmp == NULL) {
            continue;
        }
        
        printf("tmp->age:%d ", tmp->age);
    }
    
    printf("\n");
    
    // 删除元素
    while (LinkList_Length(list) > 0) {
        Teacher *tmp = (Teacher *)LinkList_Delete(list, 0);
        if (tmp == NULL) {
            continue;
        }
        
        printf("tmp->age:%d ", tmp->age);
    }
    
    LinkList_Destroy(list);
    printf("\n");

    printf("Hello, World!\n");
    return 0;
}
